﻿/*
    Function:  Northwind Db Context
    Module:    Entity Db Context
    Author:    Master HaKu(GuJinYi) 
    Date:      2012/08/16 
 */

using System.Data.Entity;
using System.Linq;
using Zeus.Biz.Northwind.Model;

namespace Zeus.Biz.DAL.EF.Northwind
{
    public class NorthwindContext : DbContext
    {
        public NorthwindContext(string connectionString)
            : base(connectionString)
        {

        }

        public DbSet<Employee> Employees { get; set; }
        public DbSet<Category> Categories { get; set; }
        public DbSet<Order> Orders { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Employee>()
                .HasMany(d => d.Orders)
                .WithOptional(l => l.Employee)
                .WillCascadeOnDelete(true);
            
            // Entity Type Configuration
            modelBuilder.Configurations.Add(new EmployeeConfiguration());
            modelBuilder.Configurations.Add(new OrderConfiguration());
        }
    }
}
